/**
 * point.h          Declaration for Point v8 class.
 * Version:         1.0
 *
 * Copyright (c) Bal Bahadur Chettri
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification, are permitted provided 
 * that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice, this list of conditions and the 
 * following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list 
 * of conditions and the following disclaimer in the documentation and/or other materials provided with the 
 * distribution.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 
 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 
 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * Last Updated: Dec 10 2011
 */
#ifndef __V8HOST_POINT_H
 #define __V8HOST_POINT_H

#include "v8class.h"
#include "v8macros.h"

V8_DECLARE_CLASS(Point)

	// declare properties / methods...
	V8_DECLARE_PROPERTIES()
		V8_PROPERTY(x)
		V8_PROPERTY(y)
	V8_END_PROPERTIES()

	V8_DECLARE_METHODS()
		V8_METHOD(clear)
	V8_END_METHODS()

public:
	V8_IMPLEMENT_EXPORT("Point");

private:
	int m_x;
	int m_y;

private:
	Point () {
		m_x = 0;
		m_y = 0;
	}
	~Point () {
		m_x = 0;
		m_y = 0;
	}

public:
	Handle<Value> Getx (Local<String> prop, const AccessorInfo &info) {
		HandleScope handle_scope;
        Local<Value> retval = Int32::New(m_x);
		return handle_scope.Close(retval);
	}

	void Setx (Local<String> prop, Local<Value> value, const AccessorInfo &info) {
        HandleScope handle_scope;
        if ( value->IsInt32() ) {
            m_x = value->Int32Value();
        } else {
            v8::ThrowException(v8::Exception::TypeError(String::New("Invalid value for x.")));
        }
	}

	Handle<Value> Gety (Local<String> prop, const AccessorInfo &info) {
		HandleScope handle_scope;
		Local<Value> retval = Int32::New(m_y);
        return handle_scope.Close(retval);
	}

	void Sety (Local<String> prop, Local<Value> value, const AccessorInfo &info) {		
		HandleScope handle_scope;
        if ( value->IsInt32() ) {
            m_y = value->Int32Value();
        } else {
            v8::ThrowException(v8::Exception::TypeError(String::New("Invalid value for y.")));
        }
	}

	Handle<Value> clear (const Arguments &args) {
		HandleScope handle_scope; 
		m_x = m_y = 0;
		return Undefined ();
	}

private:
	V8_IMPLEMENT_PROPERTY(Point,x)
	V8_IMPLEMENT_PROPERTY(Point,y)
	V8_IMPLEMENT_METHOD(Point,clear)

V8_END_CLASS(Point)

#endif /* __V8HOST_POINT_H */
